package logic

import (
	"context"
	"errors"
	"novel-hub/models/mysql"

	"novel-hub/novelrpc/internal/svc"
	"novel-hub/novelrpc/novelrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CollectionDelLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCollectionDelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CollectionDelLogic {
	return &CollectionDelLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CollectionDelLogic) CollectionDel(in *novelrpc.CollectionDelRequest) (*novelrpc.CollectionDelResponse, error) {
	// todo: add your logic here and delete this line

	var collection mysql.Collection

	if err := collection.FindCollectionById(mysql.DB, in.CollectionId); err != nil {
		return nil, err
	}
	if err := collection.CollectionDel(mysql.DB, in.CollectionId); err != nil {
		return nil, errors.New("删除失败")
	}

	return &novelrpc.CollectionDelResponse{}, nil
}
